package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.BaseActivity;
import com.sxm.yiwei.activitis.HomeHopeStoreActivity;
import com.sxm.yiwei.views.MyGridView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by KuKa on 2017/10/16.
 */

public class HopeStoreListAdapter extends BaseAdapter {
    Context context;
    List<Integer> mList;
    OnClickList onClickList;
    public HopeStoreListAdapter(Context context, List<Integer> mList) {
        this.context=context;
        this.mList=mList;
    }

    @Override
    public int getCount() {
        return mList.size()==0?0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        View view;
        if (convertView==null){
            view = LayoutInflater.from(context).inflate(R.layout.hopestore_liteitem,null);
            holder = new ViewHolder();
            holder.shopname = (TextView) view.findViewById(R.id.hopes_shopname);
            holder.gridView = (MyGridView) view.findViewById(R.id.hopes_servicegrids);
            holder.listitem = (LinearLayout) view.findViewById(R.id.hopestore_listlayout);
            view.setTag(holder);
        }else {
            view = convertView;
            holder= (ViewHolder) view.getTag();
        }
        holder.shopname.setText(mList.get(position)+" item");
        List<Integer>gList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            gList.add(mList.get(i));
        }
        holder.listitem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickList!=null){
                    onClickList.onListClick(position);
                }
            }
        });
        HopeStoreGridAdapter gridAdapter = new HopeStoreGridAdapter(context,gList);
        holder.gridView.setAdapter(gridAdapter);
        return view;
    }

    class ViewHolder{
        TextView shopname;
        MyGridView gridView;
        LinearLayout listitem;
    }
    public interface OnClickList{
        void onListClick(int p);
    }
    public void setListOnClick(OnClickList onClickList){
        this.onClickList=onClickList;
    }
}
